﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace text1
{
    public partial class main : Form
    {
        string constr = "server=LAPTOP-NHBSREVG;database=社区数据库;uid=sa;pwd=990823";
        public main()
        {
            InitializeComponent();
            //SqlConnection cnn;
           // cnn = new SqlConnection("server=LAPTOP-NHBSREVG;database=社区数据库;uid=user1;pwd=123");
            //cnn.Open();

        }


        private void Stu_Click(object sender, EventArgs e)
        {
            SqlConnection cnn = new SqlConnection(constr);
            cnn.Open();
            MessageBox.Show("成功连接数据库");
            string sql = "select * from 住户";
            //SqlCommand command = new SqlCommand(sql, cnn);
            SqlDataAdapter myDa = new SqlDataAdapter(sql,cnn);
            DataSet DS = new DataSet();
            myDa.Fill(DS,"performtable");
            dataGridView1.DataSource = DS.Tables["performtable"];
            dataGridView1.Columns[0].HeaderText = "小区编号";
            dataGridView1.Columns[1].HeaderText = "小区地址";
            dataGridView1.Columns[2].HeaderText = "小区名";
            dataGridView1.Columns[3].HeaderText = "建成时间";
            dataGridView1.Columns[4].HeaderText = "面积";
            for (int i = 0; i < dataGridView1.Columns.Count; i++)
                dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;


            /*SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                //构建一个ListView的数据，存入数据库数据，以便添加到listView1的行数据中
                ListViewItem lt = new ListViewItem();
                //将数据库数据转变成ListView类型的一行数据
                lt.Text = reader["小区编号"].ToString();
                lt.Text = reader["小区地址"].ToString();
                lt.Text = reader["小区名"].ToString();
                lt.Text = reader["建成时间"].ToString();
                lt.Text = reader["面积"].ToString();
          
                //将lt数据添加到listView1控件中
          

            }        */

            /* this.Hide();
             Stu nf = new Stu();
             nf.ShowDialog();
             this.Dispose();*/



        }

   

        private void main_Load(object sender, EventArgs e)
        {

        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void fj_Click(object sender, EventArgs e)
        {
            Fjgl nf = new Fjgl();
            nf.ShowDialog();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            fzxx n1 = new fzxx();
            n1.ShowDialog();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            zhxx n2 = new zhxx();
            n2.ShowDialog();
        }
    }
}
